<?php

	// TITLE: Auction AUTO MODEL
	// FILE: scaffolding/model/auction.php
	// AUTHOR: AUTOGEN
	// CREATED: 2015/04/20 07:49:57
	// DESCRIPTION: 
	// REQUIREMENTS: 

	$createAuction = function($con, $auction) {
		$sql = 'INSERT INTO auction (auction_id, event_id, date) VALUES (';
		$sql .= $auction->getAuctionId() . ', ';
		$sql .= $auction->getEventId() . ', ';
		$sql .= $auction->getDate() . ')';
		$sql .= ')';
		$result = mysqli_query($con, $sql);
		$id = ($result) ? mysqli_insert_id($con) : $result;
		mysqli_close($con);
		return $id;
	};

	$readAuction = function($con, $id) {
		$sql = 'SELECT * FROM auction WHERE id = ' . $id;
		$results = mysqli_query($con, $sql);
		mysqli_close($con);
		if ($results) {
			$result = mysqli_fetch_array($results);
			$auction = new Auction();
			$auction->setAuctionId($dbio->select($readAuction(result[0])));
			$auction->setEventId($dbio->select($readEvent(result[1])));
			$auction->setDate(result[2]);
		} else {
			$auction = false;
		}
		return $auction;
	};

	$updateAuction = function($con, $auction) {
		$sql = 'UPDATE auction SET ';
		$sql .= 'auction_id = ' . $auction->getAuctionId() . ', ';
		$sql .= 'event_id = ' . $auction->getEventId() . ', ';
		$sql .= 'date = ' . $auction->getDate() ;
		$sql .= 'WHERE id = ' . id;
		$result = mysqli_query($con, $sql);
		mysqli_close($con);
		return $result;
	};

	$deleteAuction = function($con, $id) {
		$sql = 'DELETE FROM auction WHERE auction_id = ' . $id;
		$result = mysqli_query($con, $sql);
		mysqli_close($con);
		return $result;
	};

	$listAuction = function($con) {
		$sql = 'SELECT * FROM auction';
		$results = mysqli_query($con, $sql);
		mysqli_close($con);
		if ($results) {
			$auctions = array();
			while ($result = mysqli_fetch_array($results)) {
				$auction = new Auction();
				$auction->setAuctionId($dbio->select($readAuction(result[0])));
				$auction->setEventId($dbio->select($readEvent(result[1])));
				$auction->setDate(result[2]);
				$auctions[] = auction;
			}// end while
		} else {
			$auctions = false;
		}
		return $auctions;
	};

